package com.sts.common.utils;

import cn.hutool.core.lang.Pair;
import com.sts.jdbc.JdbcOperation;
import com.sts.jdbc.impl.MysqlOperationImpl;
import com.sts.jdbc.impl.PostgresqlOperationImpl;
import com.sts.sink.impl.JdbcSinkImpl;
import com.sts.sink.impl.MysqlSinkImpl;
import com.sts.sink.impl.OpenGaussSinkImpl;
import com.sts.sink.impl.PostgresqlSinkImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lsl
 * @since 2025年07月04日 13:46
 */
public class DbPairUtil {

    private static final Map<String, Pair<Class<? extends JdbcSinkImpl>, Class<? extends JdbcOperation>>> DB_PAIR_MAP = new HashMap<>();

    static {
        DB_PAIR_MAP.put("MYSQL", Pair.of(MysqlSinkImpl.class, MysqlOperationImpl.class));
        DB_PAIR_MAP.put("OPENGAUSS", Pair.of(OpenGaussSinkImpl.class, PostgresqlOperationImpl.class));
        DB_PAIR_MAP.put("POSTGRESQL", Pair.of(PostgresqlSinkImpl.class, PostgresqlOperationImpl.class));
    }

    public static void registryPair(String dbType, Pair<Class<? extends JdbcSinkImpl>, Class<? extends JdbcOperation>> pair) {
        DB_PAIR_MAP.put(dbType.toUpperCase(), pair);
    }

    public static Pair<Class<? extends JdbcSinkImpl>, Class<? extends JdbcOperation>> getPair(String dbType) {
        return DB_PAIR_MAP.get(dbType.toUpperCase());
    }
}
